<template>
  <div class="mine_container">
    <template>
      <div class="user-container">
        <!-- 用户基本信息面板 -->
        <div class="user-card">
          <!-- 用户头像、姓名 -->
          <van-cell>
            <!-- 使用 title 插槽来自定义标题 -->
            <template #icon>
              <img :src="userData.user_pic" alt="" class="avatar" />
            </template>
            <template #title>
              <span class="username">{{ userData.username }}</span>
            </template>
            <template #label>
              <van-tag color="#fff" text-color="#007bff">申请认证</van-tag>
            </template>
          </van-cell>
          <!-- 动态、关注、粉丝 -->
          <div class="user-data">
            <div class="user-data-item">
              <span>0</span>
              <span>动态</span>
            </div>
            <div class="user-data-item">
              <span>0</span>
              <span>关注</span>
            </div>
            <div class="user-data-item">
              <span>0</span>
              <span>粉丝</span>
            </div>
          </div>
        </div>

        <!-- 操作面板 -->
        <van-cell-group class="action-card">
          <van-cell icon="edit" title="编辑资料" is-link @click="gotoEdit" />
          <!-- <van-cell icon="chat-o" title="小思同学" is-link /> -->
          <van-cell icon="warning-o" title="退出登录" is-link @click="logOut" />
        </van-cell-group>

        <van-dialog
          v-model="showLogOutDialog"
          title="温馨提示"
          message="确认要退出吗?"
          show-cancel-button
          @confirm="notarizeLogOut"
        >
        </van-dialog>
      </div>
    </template>
  </div>
</template>

<script>
import { getUserData } from "@/api/request.js";
export default {
  name: "Mine",
  data() {
    return {
      // 用户数据
      userData: {},
      showLogOutDialog: false,
    };
  },
  created() {
    this.getUserData();
  },
  methods: {
    // 获取用户信息
    async getUserData() {
      const { data: res } = await getUserData();
      const { status, message, data } = res;
      if (status !== 0) {
        return this.$notify({ type: "danger", message: message });
      }
      this.userData = data;
    },
    // 退出登录
    logOut() {
      this.showLogOutDialog = true;
    },
    // 确认退出
    notarizeLogOut() {
      localStorage.removeItem("token");
      this.$router.push("/login");
    },
    // 编辑资料
    gotoEdit() {
      // this.$router.push('/edit')
      this.$notify({ type: "danger", message: "因资料太少, 暂不支持编辑!" });
    },
  },
};
</script>

<style lang="less" scoped>
.user-container {
  .user-card {
    background-color: #007bff;
    color: white;
    padding-top: 20px;
    .van-cell {
      background: #007bff;
      color: white;
      &::after {
        display: none;
      }
      .avatar {
        width: 60px;
        height: 60px;
        background-color: #fff;
        border-radius: 50%;
        margin-right: 10px;
      }
      .username {
        font-size: 14px;
        font-weight: bold;
      }
    }
  }
  .user-data {
    display: flex;
    justify-content: space-evenly;
    align-items: center;
    font-size: 14px;
    padding: 30px 0;
    .user-data-item {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      width: 33.33%;
    }
  }
}
</style>
